<?php

class Product_series extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Product_series':
	 * @var integer $id
	 * @var integer $fk_bussiness_id
	 * @var string $name
	 * @var integer $priority
	 * @var integer $state
	 * @var string $create_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'product_series';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('name','length','max'=>10),
			array('name,priority', 'required'),
		);
	}

	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->fk_business_id=Yii::app()->session['business_id'];
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		$this->update_time=date('Y-m-d G:i:s');
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'fk_business_id' => '厂商id',
			'name' => '系列名称',
			'priority' => '排序优先级',
			'state' => '状态',
			'create_time' => '创建时间',
			'update_time' => '更新时间'
		);
	}
}